const CryptoJS = require('crypto-js')
const MD5 = require('crypto-js/md5')



// AES密钥以及偏移量
const key = CryptoJS.enc.Utf8.parse('1234567890000000')
const iv = CryptoJS.enc.Utf8.parse('1234567890000000')



// AES加密
const AESencrypt = (txt) => {
	let srcs = CryptoJS.enc.Utf8.parse(txt);
	return CryptoJS.AES.encrypt(srcs, key, {
		keySize: 128 / 8,
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	}).toString();
}


// AES解密
const AESdecrypt = (txt) => {
	var decrypt = CryptoJS.AES.decrypt(txt, key, {
		keySize: 128 / 8,
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
	return decryptedStr;
}

// MD5加密
const MD5encrypt = (message) => {
	let result
	result = MD5(message)
	return result + ''
}

export default {
	AESencrypt,
	AESdecrypt,
	MD5encrypt
}

